<template>
  <div>
    <div @click="handleFriendClick" class="friend-item">
      <div class="friend-avatar"> 
        <Avatar :src="friend.profile.avatar" :type="TIM.TYPES.CONV_C2C"/>
      </div>
      <div class="friend-name">{{ friend.userID }}</div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    friend: {
      type: Object,
      required: true
    }
  },
  methods:{
    handleFriendClick() {
      this.tim.getConversationProfile(`C2C${this.friend.userID}`).then(({data})=>{
        this.$store.commit('updateCurrentConversation', data);
      })
      .catch(error => {
        this.$store.commit('showMessage', { message: error.message , type: 'error' });
      });
    }
  }
}
</script>

<style scoped>
.friend-item {
  display: flex;
  padding: 10px 20px;
  cursor: pointer;
}
.friend-avatar,.friend-avatar .el-avatar{
  width: 30px;
  height: 30px;
}
.friend-name {
  color: #f7f7f8;
  line-height: 30px;
  padding-left: 10px;
  overflow: hidden;
  text-overflow:ellipsis;
}
</style>
